import {SQLite, SQLiteObject} from "@ionic-native/sqlite";

export class DataProvider {

  myAppDatabase: SQLiteObject;

  constructor(private sqlite: SQLite) {

  }

  initDatabase() {
    this.sqlite.create({
      name: 'myApp.db',
      location: 'default'
    }).then((database: SQLiteObject) => {
	  //Init user
      database.executeSql('CREATE TABLE IF NOT EXISTS users(rowId INTEGER PRIMARY KEY, username VARCHAR(20) NOT NULL, password VARCHAR(30) NOT NULL, email VARCHAR(320), gender BOOLEAN, age TINYINT, intro VARCHAR(300), phone CHAR(11), location VARCHAR(100));', {})
	  .then(() => console.log('init user successfully'))
	  .catch(e => console.log(e));
	  //Init sysinfo
      database.executeSql('CREATE TABLE IF NOT EXISTS sysinfo(rowId INTEGER PRIMARY KEY, name VARCHAR(20) NOT NULL, version VARCHAR(30) NOT NULL, createTime datetime, upTime datetime, refresh VARCHAR(100));', {})
	  .then(() => console.log('init sysinfo successfully'))
	  .catch(e => console.log(e));
      this.myAppDatabase = database;
    })
  }

}